#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

const double eps = 1e-8;

double fsqrt(double sq)
{
    double l=0,r=sq;
    double m;
    while(r-l > eps)
    {
        m = l+(r-l)/2;
        if(m*m<sq)
            l=m;
        else
            r=m;
    }
    return l;
}
double fun(double x)
{
    return (x-1)*(x-1)+3;
}
typedef double (*FUNC)(double);
double fminfun(FUNC func,double l,double r)
{
    double m1,m2;
    double ans1,ans2;
    int cnt = 0;
    while(r-l>eps){
        m1 = l + (r-l)*.382;
        m2 = l + (r-l)*.618;
        ans1 = (*func)(m1);
        ans2 = (*func)(m2);
        if(ans1<ans2)
            r = m2;
        else
            l = m1;
        cnt++;
    }
    cout<<cnt<<endl;
    return l;
}
int main()
{
    //cout<<fsqrt(4.41);
    cout<<fminfun(fun,-1e3,1e3)<<endl;
    cout<<fminfun(fun,-1e5,1e5)<<endl;
    cout<<fminfun(fun,-1e15,1e15)<<endl;
}
